﻿<?php
session_start(); //Do not remove this
	//header("location:".$_SERVER["PHP_SELF"]);//refresh
	if (!isset($_SESSION['CREATED'])) {
		$_SESSION['CREATED'] = time();
	} else if (time() - $_SESSION['CREATED'] > 600) {
		// session started more than 10 minutes ago
									//sau 10' thì thay đổi giá trị SESSION['login'] để bảo mật
			session_unset();     	// unset $_SESSION variable for this page
			session_destroy();   	// destroy session data
	}
	if (!isset($_SESSION['uploaded'])){
		$_SESSION['uploaded']=0;
	}
	if (!isset($_SESSION['imgBase64'])){
			$_SESSION['imgBase64']='/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAOAAqAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFl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Ej3RWr0zQfgn4f0Jxd3C/aLlBzcSsWcD3kclsfiKXW/il4J8BRYS4hklPCpaAMzn0Dk4Y+wJPtXNHLlTV8RUsaSxrqO1GFznNH8Ea/qEsd1qr/AGDT0YPMsIzL5Y5YBnHJxnoi/WvoG1+DHguW2hePT5JY2QFZDfTncMcHO/nNfPQ+I/jr4guYvC3h9tPs34F7doRx6jcMn6FB/vV6Rofhnxxp2i6faHVGUwW8cWEGFG1QOM5OOO5NerhqdGN1Cldd2v8AP/JHnV6lSVuepZ9l/wAA911ewj1TTLqzlXdHPE0bA9wRivhT4exfFf4SSah4CsPBcOoaXbX9zJZay9zjMLuXQGPbxjcRnJ6fdNFFetiaanZ3s9tDz6NRwurXPRLP4D+PviEyy+K/ELWNqxybOyGTj6kbQfdVU16f4K/Zn8I+EZRcLp4vL0433V2TLK31Zsk0UUqOEow95LXu9WOpiKk/db07bHqNnoFpZIFihRFHQAYq59lQfwiiiu5JI5rs/9k=';
		}
    if ($_SESSION['login']!='123!@#'){
		header('location:index.php');
	}
	
	require "../php/config.php";
	require "../php/libs/db_functions.php";
	$story_id =  isset($_GET['story_id'])? $_GET['story_id'] : 1;
	CONNECT_DB();
    mysql_query("SET NAMES utf8");
	
	$sql = "SELECT story_id, story_name FROM story_list";
	//$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());
	$result=mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
	$storylist=array();
	$indexi=0;
	while($rows=mysql_fetch_array($result)){
      $storylist[$indexi]=$rows;
	  $indexi++;
    }
?>


<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <script src="template/pages/thongke/js/highcharts.js"></script> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<link rel="shortcut icon" href="/images/favicon.ico" />
	<title>Appalication Manager</title>
	<link rel="stylesheet" href="css/main.css"/> 
	<link rel="stylesheet" href="css/tab.css"/> 
	<script src="js/using-jquery.min.js"></script>
	<script src="js/tabs.js"></script>
	 <!--<script src="js/scrolltable.js"></script>-->
  <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body onmousemove="myFunction(event)" >

<input id='macongto' type="hidden" value=''>
<!-- Container Website -->
 <div class="container">
      <!-- Header Menu -->
         
<header>
  <ul class="dark_menu">
    <li><img src="img/logo.png"></li>
    <li><a onclick = "nextpage(3)" class="" href="#" >Quản lý ứng dung</a></li>
    <li><a onclick = "nextpage(4)" class="selected" href="#">Nhập liệu ứng dụng</a></li>
	<li><a onclick = "nextpage(5)"  href="#">Quản lý người dùng</a> </li>
    <li><a onclick = "nextpage(9)" class="" href="#" class="selected">Tài khoản</a> </li>

    <ul class="user">
      <a href="#">Xin chào: <strong>
      namnt<input id = "userlogedname" type = "hidden" value = "namnt">
      </strong></a>
      <span>|</span>
      <a id = "logout" href="#">Thoát</a>
    </ul>
  </ul>
  
</header>
<section>
        <div class="time_date" style="color:#FFE8A3; font-weight:bold;">
            <a>Thời gian hệ thống: </a>
            <a><span id="miniclock"><noscript>Bật tính năng hỗ trợ JavaScript cho trình duyệt để nhìn thấy đồng hồ</noscript></span></a>
        </div>
		
</section>

<script>

$(document).ready(function(){
	//user= document.getElementById("userlogedname").value;
});
</script>      <!-- End Header Menu -->
      <!-- Navigation Time and Date --> 
      
      <!-- End Navigation Time and Date --> 
      <!-- Main Contain Datagrid Table--> 
	<div style="border:2px solid #387D18; overflow:hidden; padding:0.5%;background:#E1EEF4;">
      <div class="main-left" style="width:14%; float: left;padding-right:0.5% ">
        <div class="datagrid">
           <table>
            <thead>
              <tr>
                <th width="16%">Quản lý ứng dụng</th>
              </tr>
            </thead>
            <tbody>
              			
								<tr class="groupMeter"  >
									<td >Truyện</td>
								</tr>	
														<tr class="spaceUnder" >
															<td><img src=img/book.png style="vertical-align:middle;margin-right:3px;">
																<a onclick = "nextpage(5)" href = "#" style="color:#2E7D00; font-weight:bold;">Truyện Hay</a></td>
														</tr>	
														<tr class="spaceUnder" >
															<td><img src=img/book.png style="vertical-align:middle;margin-right:3px;">
																<a onclick = "nextpage(5)" href = "#" style="color:#2E7D00; font-weight:bold;">Sách cũ</a></td>
														</tr>	
		
								<tr class="groupMeter"  >
									<td >Trò chơi</td>
								</tr>	
														<tr class="spaceUnder" >
															<td><img src=img/book.png style="vertical-align:middle;margin-right:3px;">
																<a onclick = "nextpage(5)" href = "#" style="color:#2E7D00; font-weight:bold;">Học chữ</a></td>
														</tr>	
														<tr class="spaceUnder" >
															<td><img src=img/book.png style="vertical-align:middle;margin-right:3px;">
																<a onclick = "nextpage(5)" href = "#" style="color:#2E7D00; font-weight:bold;">Học số</a></td>
														</tr>	
            </tbody>  
          </table>
        </div>
      </div>
	<div class="main-right" style="width:85.5%; float: right; overflow:hidden;">
		<div id="wrapper1">
		  <div id="tabContainer">
			<div class="tabs">
			  <ul>
				<li id="tabHeader_1">Nhập truyện mới</li>
				<li id="tabHeader_2"><span id="tab2">Nhập chương mới của truyện</span></li>
				
			  </ul>
			</div>
			<div class="tabscontent">
			<div class="tabpage" id="tabpage_1">

				<div class="datagrid"  style="margin-top:20px;">
				   <table>
					<thead>
					  <tr >
						<th  colspan="2" >Nhập thông tin cho truyện mới/nhập tên truyện cũ và vào upload ảnh để thay ảnh đại diện</th>
					  </tr>
					</thead>
					<tbody>
						<tr height="50px">
							<td width="20%" >Tên truyện:</td>
							<td ><input type="text" name="story_name" id="story_name" size="30" placeholder="Tên Truyện" value="<?if(isset($_SESSION['_storyname'])){echo $_SESSION['_storyname'];}?>"></td>
						</tr>	
						<tr height="50px">
							<td >Insert Ảnh đại diện:</td>
							<td><input type="hidden" id="base64img" value="<?echo $_SESSION['imgBase64'];?>">
								<!--a href="crop/crop.php"><button type="button" id = "uploadimage" >Upload Image</button></a-->
								<a href="#"><button type="button" id = "uploadimage" >Upload Image</button></a>
								<span style="position: relative;">
									<img style="margin-left: 25px;margin-top: -11px;position: absolute;width: 32px;"src="data:image/jpg;base64,<?echo $_SESSION['imgBase64'];?>">
								</span>
							</td>
						</tr>	
						<tr height="50px">
							<td >Tác giả:</td>
							<td ><input type="text" name="story_author" id="story_author" size="30" placeholder="Tên tác giả"></td>
						</tr>	
						<tr height="50px">
							<td >Loại truyện:</td>
							<td ><select id="select_storytype" style="width: 213px" ><option value ="1" >Tiểu thuyết</option><option value ="2" >Kiếm hiệp</option><option value ="3" >Truyện cười</option></select></td>
						</tr>	
						<tr height="50px">
							<td >Đánh dấu Hot tag:</td>
							<td ><select id="select_hottag" style="width: 213px" ><option value ="1" >Có hot tag</option><option value ="0" >Không hot tag</option></select></td>
						</tr>	
					</tbody>  
				  </table>
				</div>
				<button type="button" id = "insert" style="margin-top:20px;">Ghi Truyện mới vào CSDL</button>
	
			</div>	
			<div class="tabpage" id="tabpage_2" >
				<div class="datagrid" style="margin-top:20px;">
				   <table>
					<thead>
					  <tr >
						<th colspan="2">Nhập Chương của Truyện và Nội dung Chương</th>
					  </tr>
					</thead>
					<tbody>
						<tr height="50px">
							<td width="20%" >Tên truyện:</td>
							<td >
								<select id='storyname' style="width: 393px">
								<?
									foreach($storylist as $story_list){
										echo '<option value='.$story_list['story_id'].'>'.$story_list['story_name'].'</option>';
									}	
								?>
								</select>
							</td>
						</tr>
						<tr>
							<td >Số thứ tự chương hiện tại</td>
							<td id="current_chapter">2</td>
						</tr>						
						<tr height="50px">
							<td >Số chương mới</td>
							<td><input type="text" name="chapter_id" id="chapter_id" size="60" value=""></td>
						</tr>
						<tr height="50px">
							<td >Tên chương</td>
							<td><input type="text" name="chapter_name" id="chapter_name" size="60" value=""></td>
						</tr>						
						<tr>
							<td >Nội dung</td>
							<td ><textarea rows="15" cols="80" id="chapter_content" ></textarea></td>
						</tr>	

					</tbody>  
				  </table>
				</div>

				<button type="button" id = "insert_chapter" style="margin-top:20px;">Ghi nội dung chương vào Truyện</button>
			</div>
			</div>
		  </div>
		</div>
		
	    
	</div> 	
	<!-- End Main Contain Datagrid Table--> 
	</div>
 </div>
<!-- End Container Website -->

<script src="js/system.js"></script>

<script>
	$(document).ready(function(){
		$('#story_name').focus();
		var story_id = $('#storyname').val();
		//alert (story_id);
			$.post('ajax/getmaxchapterid.php',{story_id: story_id}, function(data){
				//alert (data);
				//if (data!=''&&data!=null&&data!=undefined) {data = parseInt(data)+1;} else {data = 0;}
				$('#current_chapter').html(data);
				$('#chapter_id').val(parseInt(data)+1);
			});
	});
	
		$('#uploadimage').click(function(){
			var key_name = '_storyname';
			var key_value = $('#story_name').val();
			if (key_value == ''||key_value==null||key_value==undefined){
				alert ('Điền tên truyện trước khi upload ảnh!');
				return false;
			}
			//alert ('uploadimage');
			$.post('ajax/js_php_vars.php',{key_name:key_name, key_value:key_value},function(data){
				console.log(data);
				//alert (data);
				if (data=='OK'){
					window.location.href='crop/crop.php';
				}
			});
		});
		//insert story name - avatar image ...
		$('#insert').click(function(){
			alert ('xóa ảnh + xem xet vấn đề khi convert đc ảnh thì trả lại giá trị base64 vào input hidden ở trang main và cho lưu đồng loạt vào csdl thay vì rời rạc như bây giờ');
			var story_name = $('#story_name').val();
			var story_img = $('#base64img').val();
			var story_author = $('#story_author').val();
			var story_type = $('#select_storytype').val();
			var story_hot_tag =$('#select_hottag').val();
			if (story_name == ''||story_name==null||story_name==undefined||story_author == ''||story_author==null||story_author==undefined){
				alert ('Điền thông tin đầy đủ trước khi lưu vào csdl!');
				return false;
			}
			$.post('ajax/insertstory.php',{story_name:story_name, story_img:story_img, story_author: story_author, story_type: story_type, story_hot_tag: story_hot_tag}, function(data){
						alert (data);
						if (data=='successful'){
							window.location.href='crop/del.php';
						}
			});
		});
		
		$('#storyname').change(function(){
			var story_id = $(this).val();
			//alert (story_id);
			$.post('ajax/getmaxchapterid.php',{story_id: story_id}, function(data){
				//alert (data);
				//if (data!=''&&data!=null&&data!=undefined) {data = parseInt(data)+1;} else {data = 0;}
				$('#current_chapter').html(data);
				$('#chapter_id').val(parseInt(data)+1);
			});
		});
		$('#insert_chapter').click(function(){
			//alert ('Cần truyền thông tin cả vào story content và chapter list - số chương đang tăng lên 1');
			var story_id = $('#storyname').val();
			var chapter_id = $('#chapter_id').val();
			var chapter_name = $('#chapter_name').val();
			var chapter_content = $('#chapter_content').val();
			if (chapter_id == ''||chapter_id==null||chapter_id==undefined||chapter_name == ''||chapter_name==null||chapter_name==undefined||chapter_content == ''||chapter_content==null||chapter_content==undefined){
				alert ('Điền thông tin đầy đủ trước khi lưu vào csdl!');
				return false;
			}
			$.post('ajax/insert.chapter.content.php',{chapter_id:chapter_id, chapter_name:chapter_name, chapter_content: chapter_content, story_id: story_id}, function(data){
				alert (data);
			});
			
		});
		$('#logout').click(function(){
			alert('logout');
			window.location.href='logout.php';
		});
		
	</script>


</body>
</html>




